//
//  XYNavController.swift
//  WeiboSourceCode
//
//  Created by 周星宇 on 15/12/26.
//  Copyright © 2015年 cn.weibo. All rights reserved.
//

import UIKit

class XYNavController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        var backTitle = "返回"
        
        if childViewControllers.count > 0 {
            
            if childViewControllers.count == 1 { // 说明是第二个  显示上一个的标题
                
                backTitle = childViewControllers.first!.title ?? "返回"
                
            }
            viewController.hidesBottomBarWhenPushed = true
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: backTitle, action: "didClickBackBtn", target: self)
        }
        
        
        super.pushViewController(viewController, animated: true)
        
    }
    @objc private func didClickBackBtn() {
        
        popViewControllerAnimated(true)
        
    }
    
}
